package com.zeldu.student.controller;

import com.zeldu.common.model.response.CommonCode;
import com.zeldu.common.model.response.ResponseResult;
import com.zeldu.student.pojo.Student;
import com.zeldu.student.service.StudentInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class StudentInfoController {

    @Autowired(required = false)
    private StudentInfoService studentInfoService;

    @GetMapping("/getSelfInfo")
    public Student getSelfInfo(Long id) {
        return studentInfoService.getSelfInfo(id);
    }

    @PostMapping("/mdfSelfInfo")
    public ResponseResult mdfSelfInfo(@RequestBody Student student) {
        if (studentInfoService.mdfSelfInfo(student) != 0) {
            return new ResponseResult((CommonCode.SUCCESS));
        } else {
            return new ResponseResult((CommonCode.FAIL));
        }
    }

    @GetMapping("/joinClass")
    public ResponseResult joinClass(Student student) {
        if (studentInfoService.joinClass(student) != 0) {
            return new ResponseResult((CommonCode.SUCCESS));
        } else {
            return new ResponseResult((CommonCode.FAIL));
        }
    }

    @GetMapping("getClassName")
    public String getClassName(Long id) {
        return studentInfoService.getClassName(id);
    }
}
